<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <link rel="stylesheet" href="media/layui/css/layui.css">
</head>
<body>

<script src="media/layui/layui.js"></script>
<script src="media/js/jquery.min.js"></script>


<!--表格的展示-->
<div id="table">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<!--工具条的显示-->
<script type="text/html" id="barDemo">
    <button class="layui-btn" lay-event="detail">详情</button>
    <button class="layui-btn" lay-event="cancel">取消</button>
    <!--  <a class="layui-btn layui-btn-xs" lay-event="edit">预定</a>-->
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>


<script>
    layui.use(['table', 'laydate', "laypage", "layer", 'carousel', 'upload', 'element'], function(){
        //初始化table组件对象
        var table = layui.table
            ,laypage =layui.laypage//分页的组件
            ,layer = layui.layer//弹框
            ,laydate = layui.laydate//日期组件
            ,element = layui.element;//元素的操作

        //渲染table
        table.render({
            //z找到table  id叫test的组件
            elem: '#test'
            ,id:"table"
            ,url:"seller/order/list"
            ,totalRow: true
            //这个很关键，就是解析 json数据库中数据的 一定要注意键值
            ,cols: [[
                {field:'orderId', title:'订单号', unresize: true, sort: true, fixed:"left"}
                ,{field:'buyerName', title:'买家名字'}
                ,{field:'buyerPhone', title:'手机号'}
                ,{field:'buyerAddress', title:'地址'}
                ,{field:'orderAmount', title:'金额'}
                ,{field:'orderStatus', title:'订单状态',templet: function(item){
                        //    NEW(0,"新订单"),
                        //    FINISHED(1,"完结"),
                        //    CANCLE(2,"已取消"),
                        var str = ""
                        if (item.orderStatus == 0){
                            str = "新订单";
                        }else if (item.orderStatus ==1){
                            str = "完结";
                        }else {
                            str = "已取消";
                        }


                        return '<span style="color: #c00;">'+str +'</span>'
                    }}
                ,{field:'payStatus', title:'支付状态',
                    templet: function(item){
                        //    WAIT(0,"未支付"),
                    //    SUCCESS(1,"支付成功"),
                        var str = ""
                        if (item.payStatus == 0){
                            str = "未支付";
                        }else if (item.payStatus ==1){
                            str = "支付成功";
                        }

                        return '<span style="color: #c00;">'+str +'</span>'
                    }
                }
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width: 300}
            ]]
            ,page: true //分页开启


        });

        /*监听行工具事件*/
        table.on('tool(test)',function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'cancel') {
                $.ajax({
                    type:"get",
                    url:"seller/order/cancel?orderId="+ data.orderId,
                    dataType:"json",
                    success:function(data){
                        alert(data.msg);
                        window.location.href="http://localhost:8080/sell/orderlist.html";
                    },
                    error : function(){
                        alert("ajax加载失败");
                    }

                })
            }

            if (obj.event === 'detail') {
                /* $.ajax({
                     type:"get",
                     url:"week/update.do?id="+ data.id,
                     dataType:"json",
                     success:function(data){
                         alert(data.info);
                         window.location.href="http://localhost:8080/OaNew/week.html";
                     },
                     error : function(){
                         alert("ajax加载失败");
                     }

                 })*/

                window.location.href = "weekUpdate.html?id=" + data.id
            }
        })

    });
</script>

</body>
</html>
